<script type="text/html" template>
    <title>{{layui.setter.MenuName}}-{{layui.setter.name}}</title>
</script>
<style>
    .layui-table-cell {
        height: auto !important;
        font-size:0.85em;
    }

    .layui-table-body table {
        height: inherit !important;
    }
    
    .xm-select-dl{
        width:380px !important;
    }
    .xm-select-linkage .xm-select-linkage-group li {
        height:24px;
        line-height:24px
    }
    .xm-select-linkage .xm-select-linkage-group li span{
       line-height:24px
    }
    .layui-tab-title li {
        font-size: 0.8em;
    }
    .layui-card-header {
        border-bottom:none;
    }
    .layui-tab-item{
        margin-top: -8px;
    }


    /* 表格内商品样式 */
    .product-item {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        height: 52px;
        border-bottom: 0.5px solid rgba(204, 204, 204, 0.67);
        /* padding: 10px 0 */
    }

    .product-item:last-child {
        border-bottom: 0
    }

    .product-img {
        width: 38px;
        height: 38px;
        border: 1px solid #ccc;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .product-img img {
        width: 38px;
        height: auto
    }

    .product-name {
        height: 46px;
        flex: 1;
        overflow: hidden;
        line-height: 46px;
        margin-left: 12px;
        font-weight: bold;
        /*color: black;*/
    }

    .product-tool {
        display: flex;
        justify-content: flex-end;
        align-items: flex-end;
        /*flex-direction: column;*/
        height:52px !important;
        /*line-height: 52px;*/
        border-left:1px solid #f2f2f2;
        padding-left:5px;
        width:80px;
        display: flex;
        justify-content: center;
        align-items: center;
        text-align:center;
    }

    .product-tool span {
        display: block;
        /*height: 32px;
        line-height: 32px;*/
        /*margin-left: 12px;*/
    }

    .font2 {
        color: #098db7;
        font-weight: 500;
        text-decoration: underline;
        cursor: pointer;
    }

    .span1{
        color:#a9a9a9;
        font-size:0.8em;
    }
    .span2{
        color:#838383;
        font-size:0.8em;
        font-weight:bold;
    }
    .span3{
        color:#4e91b2;
        font-size:0.8em;
        font-weight:bold;
        text-decoration:underline;
        text-decoration-color:rgba(21, 145, 185, 0.67);
        cursor:pointer;
    }
    .span4{
        color:#575757;
        font-weight:bold;
        font-size:13px;
    }
    .span5{
        color:#F08080;
        font-weight:bold;
        font-size:13px;
    }
    .span6{
        font-size:14.5px;
        color:#FF4500;
        font-weight:bold;
    }
    .icon1{
        color:rgba(222, 178, 35, 0.69);
        font-size:0.7em;
    }
    .bksp{
        color:white;
        background:#FF4500;
        border:1px solid #FF4500;
        border-radius:3px;
        cursor:pointer;
    }
    
    /* 表格内商品样式 */
</style>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <script type="text/html" template>
            <a><cite>{{layui.setter.MenuName}}</cite></a>
        </script>
    </div>
</div>


<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">订单号</label>
                    <div class="layui-input-inline" style="width:180px;">
                        <input type="text" name="orderCode" id="orderCode" placeholder="订单号/交易单号" autocomplete="off"
                            class="layui-input">
                    </div>
                    <!--<label class="layui-form-label">自提码</label>
                    <div class="layui-input-inline" style="width:150px;">
                        <input type="text" name="SelfCode" id="SelfCode" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>-->
                    <label class="layui-form-label">商品名称</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="GoodSelector" id="GoodSelector"
                            placeholder="">
                    </div>
                    <label class="layui-form-label">下单时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="test6" readonly="readonly" placeholder=" - ">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">商品分类</label>
                    <div class="layui-input-inline" style="width:180px;">
                        <select name='cateID' xm-select="cateID" id='cateID' xm-select-radio="" xm-select-search="">
                            <option value=""></option>
                        </select>
                    </div>
                    <label class="layui-form-label">收货信息</label>
                    <div class="layui-input-inline" style="width:150px;">
                        <input type="text" name="receiveKey" id="receiveKey" placeholder="收货人姓名/电话" autocomplete="off" class="layui-input">
                    </div>
                    <!--<label class="layui-form-label">供应商</label>
                    <div class="layui-input-inline">
                        <select name="SupplierSelector" xm-select="SupplierSelector" xm-select-search xm-select-skin="default">
                            <option value=""></option>
                        </select>
                    </div>
                    <label class="layui-form-label">店铺名称</label>
                    <div class="layui-input-inline">
                        <select name="StoreSelector" xm-select="StoreSelector" xm-select-search xm-select-skin="default">
                            <option value=""></option>
                        </select>
                    </div>-->
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-delete">
                        <i class="layui-icon layui-icon-delete layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-tab" lay-filter="ordertabs" style="margin-top:-12px;">
            <ul class="layui-tab-title" style="font-size:0.8em;">
                <li index="0">待发货</li>
                <li index="1">待支付</li>
                <li index="2">已发货</li>
                <li index="3">已完成</li>
                <li index="4">已取消</li>
                <li index="6">全部订单</li>
            </ul>

            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show" id="LAY-app-content-listitem">
                    <!--table1-->
                    <div class="layui-card-body">
                        <div style="padding-bottom: 2px;">
                            <button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="view">查看</button>
                            <button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="sendGoods">邮寄发货</button>
                            <!--<button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="writeoff">核销发货</button>
                            <button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="selfmention">自提发货</button>-->
                            <!-- <button class="layui-btn layuiadmin-btn-list" data-type="clostOrders">关闭</button> -->
                        </div>
                        <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
                    </div>
                    <!--table1 待发货-->
                </div>

                <div class="layui-tab-item" id="LAY-app-content-list1item">
                    <div class="layui-card-body">
                        <div style="padding-bottom: 2px;">
                            <button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="view">查看</button>
                            <!-- <button class="layui-btn layuiadmin-btn-list" data-type="clostOrders">关闭</button> -->
                        </div>
                        <table id="LAY-app-content-list1" lay-filter="LAY-app-content-list1"></table>
                    </div>
                    <!-- table1 待支付 -->
                </div>

                <div class="layui-tab-item" id="LAY-app-content-list2item">
                    <div class="layui-card-body">
                        <div style="padding-bottom: 2px;">
                            <button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="view">查看</button>
                            <button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="recall">撤回</button>
                        </div>
                        <!--table1-->

                        <table id="LAY-app-content-list2" lay-filter="LAY-app-content-list2"></table>
                    </div>
                    <!--table1 已发货-->
                </div>
                <div class="layui-tab-item" id="LAY-app-content-list3item">
                    <div class="layui-card-body">
                        <div style="padding-bottom: 2px;">
                            <button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="view">查看</button>
                        </div>
                        <!--table1-->

                        <table id="LAY-app-content-list3" lay-filter="LAY-app-content-list3"></table>
                    </div>
                    <!--table1 已完成-->
                </div>
                <div class="layui-tab-item" id="LAY-app-content-list4item">
                    <div class="layui-card-body">
                        <div style="padding-bottom: 2px;">
                            <button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="view">查看</button>
                        </div>
                        <!--table1-->

                        <table id="LAY-app-content-list4" lay-filter="LAY-app-content-list4"></table>
                    </div>
                    <!--table1 已取消-->
                </div>
                <div class="layui-tab-item" id="LAY-app-content-list5item">
                    <div class="layui-card-body">
                        <div style="padding-bottom: 2px;">
                            <button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="view">查看</button><button
                                class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="sendGoods">发货</button>
                        </div>
                        <!--table1-->
                        <table id="LAY-app-content-list5" lay-filter="LAY-app-content-list5"></table>
                        <!--table1 全部订单-->
                    </div>
                </div>


            </div>
        </div>
    </div>
</div>


<script>

    layui.data["currentTable"] = "LAY-app-content-list";

    layui.data.setActive = function () {
        var $ = layui.$;
        var form = layui.form;
        var admin = layui.admin;
        var view = layui.view;
        var table = layui.table;
    }

    layui.use('hzcg_Order', layui.factory('hzcg_Order')).use(['admin', 'table', 'element', 'laydate', 'formSelects'], function () {

        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , form = layui.form;
        var laydate = layui.laydate;
        var element = layui.element;
        var formSelects = layui.formSelects;


        laydate.render({
            elem: '#test6',
            range: '~' //指定元素
        });


        formSelects.config('SupplierSelector', {
            keyName: 'title',            //自定义返回数据中name的key, 默认 name
            keyVal: 'id',            //自定义返回数据中value的key, 默认 value
            keyChildren: 'children',    //联动多选自定义children
        });

        admin.req({
            url: layui.setter.APIUrl + '/shop/supplierMgr/customerQueryChildren2', //实际使用请改成服务端真实接口
            type: 'post',
            done: function (res) {
                layui.formSelects.data('SupplierSelector', 'local', {
                    arr: res.Data,
                    linkage: true,
                    linkageWidth: 100
                });
            }
        });
        formSelects.on('SupplierSelector', function (id, vals, val, isAdd, isDisabled) {
            if (isAdd == true) {
                if (val.value.indexOf("/") <= 0 || ((val.value.split('/')).length - 1) < 2) {
                    isAdd = false;
                    return false;
                }
            }
        });


        formSelects.config('StoreSelector', {
            keyName: 'title',            //自定义返回数据中name的key, 默认 name
            keyVal: 'id',            //自定义返回数据中value的key, 默认 value
            keyChildren: 'children',    //联动多选自定义children
        });

        admin.req({
            url: layui.setter.APIUrl + '/shop/storeMgr/customerQueryChildren2', //实际使用请改成服务端真实接口
            type: 'post',
            done: function (res) {
                layui.formSelects.data('StoreSelector', 'local', {
                    arr: res.Data,
                    linkage: true,
                    linkageWidth: 120
                });
            }
        });
        formSelects.on('StoreSelector', function (id, vals, val, isAdd, isDisabled) {
            if (isAdd == true) {
                if (val.value.indexOf("/") <= 0) {  //多级选择时,第一级无法选中
                    isAdd = false;
                    return false;
                }
            }
        });


        formSelects.config('cateID', {
            keyName: 'title',            //自定义返回数据中name的key, 默认 name
            keyVal: 'id',            //自定义返回数据中value的key, 默认 value
            keyChildren: 'children',    //联动多选自定义children
        });

        admin.req({
            url: layui.setter.APIUrl + '/shop/GoodsCategoryMgr/customerQueryChildren', //实际使用请改成服务端真实接口
            type: 'post',
            done: function (res) {
                layui.formSelects.data('cateID', 'local', {
                    arr: res.Data,
                });
            }
        });
        //这里也算是给自己挖了一手好坑吧, 简单的一种处理方式, 在多选第一次打开的时候收缩所有的子节点, 目前处理的很粗鲁, 就是为了一种效果, 收缩全部节点
        var isFirst = true;
        layui.formSelects.opened('cateID', function (id) {
            if (isFirst) {
                isFirst = false;
                $('[fs_id="cateID"]').find('.xm-cz i.icon-caidan').click();
            }
        });

        form.render(null, 'app-content-list');

        //表格上面的按钮
        var active = {
            sendGoods: function () {
                var checkStatus = layui.table.checkStatus(layui.data["currentTable"])
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length !== 1) {
                    return layer.msg('请选择一条数据');
                }

                var ids = "";
                var isWoryState = false;

                $.each(checkData, function (index, eobj) {
                    if (!(eobj.State_Sel == 1 || eobj.State_Sel == 2)) {
                        layer.msg('选中订单目前状态不可发货，请重新选择！');
                        isWoryState = true;
                    }
                    if (eobj.DistributionMode_Sel != 1) {
                        layer.msg('只有快递配送的才能邮寄发货！');
                        isWoryState = true;
                    }
                    ids += "," + eobj.PID;
                });

                if (isWoryState) { return; }

                if (ids.indexOf(',') == 0)
                    ids = ids.substr(1);

                admin.popup({
                    title: '发货'
                    , skin: 'layui-layer-lan'
                    , area: ['80%', '96%']
                    , id: 'LAY-popup-content-add'
                    , success: function (layero, index) {
                        view(this.id).render('/shop/shop_order/SendGood').done(function () {
                            form.on('submit(layuiadmin-app-form-submit)', function (formdata) {
                                var field = formdata.field; //获取提交的字段

                                //发送接口数据
                                if (!field.ExpressCode || !field.ExpressNumber) {
                                    alert("请填写快递公司和运单号码！");
                                    return;
                                }

                                admin.req({
                                    url: layui.setter.APIUrl + '/shop/order_DeliverMgr/sendData' //实际使用请改成服务端真实接口
                                    , data: { "orderIds": ids, 'data': JSON.stringify(field), dtype: 0 }
                                    , type: "post"
                                    // , success: function (res) {
                                    // }
                                    , done: function (res) {
                                        layer.closeAll(); //执行关闭 
                                        table.reload(layui.data["currentTable"]);
                                        //table.reload('LAY-app-content-list7');


                                        layer.msg('发货成功');
                                    }
                                });
                            });
                        });
                    }
                });
            },
            //核销
            writeoff: function () {
                var checkStatus = layui.table.checkStatus(layui.data["currentTable"])
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }

                var ids = "";
                var isWoryState = false;

                $.each(checkData, function (index, eobj) {
                    if (!(eobj.State_Sel == 1 || eobj.State_Sel == 2)) {
                        layer.msg('选中订单目前状态不可发货，请重新选择！');
                        isWoryState = true;
                    }
                    ids += "," + eobj.PID;
                });

                if (ids.indexOf(',') == 0)
                    ids = ids.substr(1);

                if (isWoryState) { return; }

                layer.confirm('确定核销吗？', function (index) {
                    var field = new Object();
                    field.ExpressCode = "核销";
                    field.ExpressNumber = "核销";
                    admin.req({
                        url: layui.setter.APIUrl + '/shop/order_DeliverMgr/sendData' //实际使用请改成服务端真实接口
                        , data: { "orderIds": ids, 'data': JSON.stringify(field), dtype: 2 }
                        , type: "post"
                        , done: function (res) {
                            layer.closeAll(); //执行关闭 
                            table.reload(layui.data["currentTable"]);
                            layer.msg('核销发货成功');
                        }
                    });

                });

            },

            selfmention: function () {
                var checkStatus = layui.table.checkStatus(layui.data["currentTable"])
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }

                var ids = "";
                var isWoryState = false;
                $.each(checkData, function (index, eobj) {
                    if (!(eobj.State_Sel == 1 || eobj.State_Sel == 2)) {
                        layer.msg('选中订单目前状态不可发货，请重新选择！');
                        isWoryState = true;
                    }
                    if (!(eobj.DistributionMode_Sel != 1)) {
                        layer.msg('只有自提订单的才能自提发货！');
                        isWoryState = true;
                    }
                    ids += "," + eobj.PID;
                });

                if (isWoryState) { return; }

                if (ids.indexOf(',') == 0)
                    ids = ids.substr(1);


                layer.confirm('确定自提发货吗？', function (index) {
                    var field = new Object();
                    field.ExpressCode = "自提";
                    field.ExpressNumber = "自提";
                    admin.req({
                        url: layui.setter.APIUrl + '/shop/order_DeliverMgr/sendData' //实际使用请改成服务端真实接口
                        , data: { "orderIds": ids, 'data': JSON.stringify(field), dtype: 1 }
                        , type: "post"
                        , done: function (res) {
                            layer.closeAll(); //执行关闭 
                            table.reload(layui.data["currentTable"]);
                            layer.msg('自提发货成功');
                        }
                    });

                });

            },

            view: function () {
                var checkStatus = layui.table.checkStatus(layui.data["currentTable"])
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length !== 1) {
                    return layer.msg('请选择数据');
                }

                admin.popup({
                    title: '查看信息'
                    , area: ['90%', '96%']
                    , id: 'LAY-popup-content-view'
                    , success: function (layero, index) {
                        view(this.id).render('/shop/shop_Order/orderDetail', checkData[0]).done(function () {
                            //监听提交
                            form.on('submit(layuiadmin-app-form-submit)', function (data) {
                                layer.close(index); //执行关闭
                            });
                        });
                    }
                });
            },

            //撤回
            recall: function () {
                var checkStatus = layui.table.checkStatus(layui.data["currentTable"])
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length !== 1) {
                    return layer.msg('请选择一条数据');
                }

                var ids="";
                var isWoryState=false;

                $.each(checkData, function (index, eobj) {
                    if (!(eobj.State_Sel == 3)) {
                        layer.msg('数据选中有不是部分发货，请重新选择！');
                        isWoryState = true;
                    }
                    ids += "," + eobj.PID;
                });

                if (isWoryState) { return; }

                if (ids.indexOf(',') == 0)
                    ids = ids.substr(1);

                layer.confirm('确定撤回发货吗？', function (index) {
                    admin.req({
                        url: layui.setter.APIUrl + '/shop/order_DeliverMgr/recall' //实际使用请改成服务端真实接口
                        , data: { "ids": ids }
                        , type: "post"
                        , done: function (res) {
                            layer.closeAll(); //执行关闭 
                            table.reload(layui.data["currentTable"]);
                            layer.msg(res.ResultInfo);
                        }
                    });
                });
            }
        };

        $('.layui-btn.layuiadmin-btn-list').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        element.on('tab(ordertabs)', function (data) {
            data.index = this.attributes['index'].value;

            if (data.index == 0) {
                beforeTabinit("LAY-app-content-list", 1)
            }

            if (data.index == 1) {
                beforeTabinit("LAY-app-content-list1", 0)
            }

            if (data.index == 2) {
                beforeTabinit("LAY-app-content-list2", 3)
            }

            if (data.index == 3) {
                beforeTabinit("LAY-app-content-list3", 4)
            }

            if (data.index == 4) {
                beforeTabinit("LAY-app-content-list4", 5)
            }

            if (data.index == 5) {
                beforeTabinit("LAY-app-content-list6", 6)
            }

            if (data.index == 6) {
                beforeTabinit("LAY-app-content-list5", null)
            }

            // if (data.index == 7) {
            //     beforeTabinit("LAY-app-content-list7", 7)
            // }
        });

        function beforeTabinit(name, index) {
            tableinit(name, index)
            layui.data["currentTable"] = name;
            layui.data["currentTableIndex"] = index;

            var initData = {
                state: index
            }
            // statice(initData);
        }

        function resText(d) {
            var tableText = "";

            var groupBit = "";
            if (d.IsGroupBuy == 1) {
                groupBit += "<span class='bksp' style='margin-left:15px;' title='团购订单'>团</span>";
            }

            if (d.State_Sel == 0) {
                tableText += `<div style="border-bottom: 1px solid #f2f2f2;margin: 0 -15px;padding: 0 15px; background-color: #f2f2f2;">
                                 <span class='span1'>${d.CreateTime}</span>　　 <span class='span1'>订单号：</span><span class='span3' lay-event="view" title='点击查看订单详情'>${d.OrderNumber}</span> ${groupBit}
                                 <span style='float:right'><span class='span1'>交易单号：</span><span class='span3' lay-event="changePrice" title='点击查看交易单'>${d.BillCodestr}</span></span>
                              </div>`
            } else {
                tableText += `<div style="border-bottom: 1px solid #f2f2f2;margin: 0 -15px;padding: 0 15px; background-color: #f2f2f2;">
                                 <span class='span1'>${d.CreateTime}</span>　　 <span class='span1'>订单号：</span><span class='span3' lay-event="view" title='点击查看订单详情'>${d.OrderNumber}</span>  ${groupBit}
                                 <span style='float:right'><span class='span1'>交易单号：</span><span class='span3' lay-event="changePrice" title='点击查看交易单'>${d.BillCodestr}</span></span>
                              </div>`
            }

            $.each(d.Goods, function (index, eobj) {
                tableText += `
            <div class="product-item">
            <div class="product-img">
                <img  src="${ layui.setter.ImgPath + eobj.Path_Upload}" />
            </div>
            <div class="product-name">
                <p style='height:20px;margin-top:-12px'>${eobj.Name}</p>
                <p style='height:20px;color:#9f9f9f'>${eobj.Specifications}</p>
            </div>
            <div class="product-tool">
               * &nbsp;<span class='span4'>${eobj.Count}<span>
            </div>
            <div class="product-tool" style="border-left:1px solid #f2f2f2; padding-left:5px;width:80px;display: flex;justify-content: center;align-items: center;">
              <span style='color:#F08080'>￥</span><span class ='span5'>${eobj.Price}<span>
            </div>
        </div>
            `
            });
            return tableText;
        }

        var colsdata = [[
            { type: 'checkbox', fixed: 'left', field: 'PID', totalRowText: '合计行' }, //sort: true  //hide: true //  width:100  
            {
                field: 'orderDetail', title: '订单详情', minWidth: 560, templet: function (d) {
                    return resText(d);
                }
            },
            {
                field: 'PayPrice', title: '订单金额', width: 90, templet: function (d) {
                    var srt = `<div style='padding-top:30px;text-align:center;' ><span style='color:#FF4500'>￥</span><span class='span6'>${d.PayPrice}</span></div>`;
                    return srt;
                }, totalRow: true
            },
            {
                field: 'storeName', title: '店铺/供应商', width: 90, templet: function (d) {
                    var btnText = "";
                    if (d.storeName) {
                        btnText += "<span class='span1'></span>" + d.storeName
                    }
                    if (d.SupplierName) {
                        btnText += "<br/><span class='span1'></span>" + d.SupplierName
                    }
                    return btnText;
                }, width: 170
            },
            {
                field: 'CreateTime', title: '配送信息', width: 120, templet: function (d) {

                    var btnText = "";

                    if (d.DistributionMode_Sel == 1) {
                        btnText += "<span style='color:#1E9FFF;font-weight:bold'>快递</span>";
                    } else {
                        btnText += "<span style='color:#483D8B;font-weight:bold'>自提</span>";
                    }

                    if (d.PickCode) {
                        btnText += "<br/><span class='icon1' title='自提码'><i class='layui-icon'>&#xe673;</i></span> <span style='font-weight:bold;font-size:1.1em' title='自提码'>" + d.PickCode + "</span>";
                    }

                    return btnText;
                }
            },
            {
                field: 'State_Sel', title: '订单状态', width: 80, templet: function (d) {
                    var btnText = "";
                    var State_Sel = d.State_Sel;
                    var strDes = '订单状态[0.待支付|1.待发货|2.部分发货|3.发货完成|4.已完成|5.取消|6.关闭]';
                    if (d.State_Sel == 0) {
                        btnText += "<span style='color:#FFA500;font-weight:bold'>待支付</span>";
                    } else if (d.State_Sel == 1) {
                        btnText += "<span style='color:#3CB371;font-weight:bold'>待发货</span>";
                    } else if (d.State_Sel == 2) {
                        btnText += "<span style='color:#5F9EA0;font-weight:bold'>部分发货</span>";
                    } else if (d.State_Sel == 3) {
                        btnText += "<span style='color:#4682B4;font-weight:bold'>已发货</span>";
                    } else if (d.State_Sel == 4) {
                        btnText += "<span style='color:#5FB878;font-weight:bold'>已完成</span>";
                    } else if (d.State_Sel == 5) {
                        btnText += "<span style='color:#A9A9A9;font-weight:bold'>取消</span>";
                    } else if (d.State_Sel == 6) {
                        btnText += "<span style='color:#c2c2c2;font-weight:bold'>关闭</span>";
                    } else {
                        btnText += "<span style='color:#c2c2c2;font-weight:bold'>未知</span>";
                    }
                    return btnText;
                }, minWidth: 80, align: 'center'
            },
            {
                field: 'UserName', title: '收货信息', style: "", width: 230, templet: function (d) {
                    var srt = "<div>";
                    srt += "" + d.UserName + " ";
                    srt += "" + d.UserTel + "";
                    srt += "<br/>" + d.UserAddress + "";

                    if (d.State_Sel == 1) {
                        srt += "<br/><a class='font2' lay-event=\"updatesh\">修改</a>";
                    }
                    srt += "</div>";
                    return srt;
                }
            }
        ]];

        function tableinit(element, state) {
            table.render({
                elem: "#" + element
                , toolbar: false  //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                , defaultToolbar: ['filter']
                , method: "post"
                , totalRow: true
                , url: layui.setter.APIUrl + '/Shop/orderMgr/listPain'
                , where: { state: state }
                , headers: { //通过 request 头传递
                    Authorization: "bearer " + layui.data('layuiAdmin').access_token
                }
                , parseData: function (res) { //res 即为原始返回的数据 
                    varButtonRight = res.Data.ButtonRight;
                    return {
                        "ResultCode": res.ResultCode, //解析接口状态
                        "ResultInfo": res.ResultInfo, //解析提示文本
                        "count": res.Data.TotalRecordCount, //解析数据长度
                        "Data": res.Data.Items //解析数据列表 
                    };
                },
                done: function () {
                    var objtable0 = $("#" + element + "item .layui-table")[1];
                    var objtable1 = $("#" + element + "item  .layui-table")[3];
                    var objtable2 = $("#" + element + "item  .layui-table")[5];
                    $(objtable0).find("tr").each(function (index, obj) {
                        var objtr1 = $(objtable1).find("tr")[index];
                        $(objtr1).attr("height", obj.scrollHeight);
                        var objtr2 = $(objtable2).find("tr")[index];
                        $(objtr2).attr("height", obj.scrollHeight);
                    })
                    // $(".layui-tab-item .layui-show .layui-table").attr("style", "height: inherit !important;");
                }
                , cols: colsdata
                , page: true
                , limit: 10
                , limits: [10, 15, 20, 25, 30]
                , text: {
                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增 text: '对不起，加载出现异常！'
                }
            });
            table.on('tool(' + element + ')', function (obj) {
                var data = obj.data;
                if (obj.event === 'changePrice') {
                    admin.popup({
                        title: '交易单信息'
                        , area: ['58%', '76%']
                        , id: 'LAY-popup-content-updatesh'
                        , success: function (layero, index) {
                            view(this.id).render('/shop/shop_Order/orderChangeFare', data).done(function () {
                                form.render(null, 'layuiadmin-app-form-list');
                                //监听提交
                                form.on('submit(layuiadmin-app-form-submit)', function (data) {
                                    var field = data.field; //获取提交的字段 
                                    //提交 Ajax 成功后，关闭当前弹层并重载表格 

                                    admin.req({
                                        url: layui.setter.APIUrl + '/shop/BillflowMgr/ChangeFarePrice' //实际使用请改成服务端真实接口
                                        , data: { billcode: field.BillCode, price: field.FarePrice }
                                        , type: "post"
                                        , done: function (res) {
                                            if (res.ResultCode == 0) {
                                                table.reload(layui.data["currentTable"]);
                                                //layui.table.reload('LAY-app-content-list7'); //重载表格
                                                layer.close(index); //执行关闭
                                                layer.msg('修改成功');
                                            } else {
                                                layer.msg(res.ResultInfo);
                                            }
                                        }
                                    });
                                });
                            });
                        }
                    });

                }
                else if (obj.event === 'updatesh') {
                    admin.popup({
                        title: '修改收货信息'
                        , area: ['660px', '500px']
                        , id: 'LAY-popup-content-updatesh'
                        , success: function (layero, index) {
                            view(this.id).render('/shop/shop_Order/updatesh', data).done(function () {
                                form.render(null, 'layuiadmin-app-form-list');
                                //监听提交
                                form.on('submit(layuiadmin-app-form-submit)', function (data) {
                                    var field = data.field; //获取提交的字段 
                                    //提交 Ajax 成功后，关闭当前弹层并重载表格 
                                    admin.req({
                                        url: layui.setter.APIUrl + '/shop/orderMgr/updateSH' //实际使用请改成服务端真实接口
                                        , data: field
                                        , type: "post"
                                        , done: function (res) {
                                            table.reload(layui.data["currentTable"]);
                                            //layui.table.reload('LAY-app-content-list7'); //重载表格
                                            layer.close(index); //执行关闭
                                            layer.msg('修改成功');
                                        }
                                    });
                                });
                            });
                        }
                    });
                }
                else if (obj.event === 'view') {
                    admin.popup({
                        title: '查看信息'
                        , area: ['90%', '96%']
                        , id: 'LAY-popup-content-view'
                        , success: function (layero, index) {
                            view(this.id).render('/shop/shop_Order/orderDetail', data).done(function () {
                                //监听提交
                                form.on('submit(layuiadmin-app-form-submit)', function (data) {
                                    layer.close(index); //执行关闭
                                });
                            });
                        }
                    });
                }
                else if (obj.event == "sendGoods") {
                    //
                    admin.popup({
                        title: '发货'
                        , skin: 'layui-layer-lan'
                        , area: ['80%', '96%']
                        , id: 'LAY-popup-content-add'
                        , success: function (layero, index) {
                            view(this.id).render('/shop/shop_order/SendGood').done(function () {
                                form.on('submit(layuiadmin-app-form-submit)', function (formdata) {
                                    var field = formdata.field; //获取提交的字段
                                    //发送接口数据
                                    if (!field.ExpressCode || !field.ExpressNumber) {
                                        alert("请填写快递公司和运单号码！");
                                        return;
                                    }
                                    admin.req({
                                        url: layui.setter.APIUrl + '/shop/order_DeliverMgr/sendData' //实际使用请改成服务端真实接口
                                        , data: { "orderIds": data.PID, 'data': JSON.stringify(field), dtype: 0 }
                                        , type: "post"

                                        , done: function (res) {
                                            layer.closeAll(); //执行关闭 
                                            table.reload(layui.data["currentTable"]);
                                            layer.msg('发货成功');
                                        }
                                    });
                                });
                            });
                        }
                    });
                }
                else if (obj.event == "writeoff") {
                    layer.confirm('确定核销吗？', function (index) {

                        field.ExpressCode = "核销";
                        field.ExpressNumber = "核销";
                        admin.req({
                            url: layui.setter.APIUrl + '/shop/order_DeliverMgr/sendData' //实际使用请改成服务端真实接口
                            , data: { "orderIds": data.PID, 'data': JSON.stringify(field), dtype: 2 }
                            , type: "post"
                            , done: function (res) {
                                layer.closeAll(); //执行关闭 
                                table.reload(layui.data["currentTable"]);
                                layer.msg('发货成功');
                            }
                        });

                    });
                }
                else if (obj.event == "selfmention") {

                }

            })

        }

        beforeTabinit("LAY-app-content-list", 1);

        form.on('submit(LAY-app-contlist-delete)', function (data) {
            $("#test6").val('');
            $("#key").val('');
            $("#orderCode").val('');
            $("#GoodSelector").val('');
            //$("#SupplierSelector").val('');
            layui.formSelects.value('SupplierSelector', []);
            layui.formSelects.value('StoreSelector', []);
            $("#receiveKey").val('');
            //$("#cateID").val('');
            layui.formSelects.value('cateID', []);
            $("#SelfCode").val('');

            form.render("select");

            table.reload(layui.data["currentTable"], {
                where: {
                    startTime: "",
                    endTime: "",
                    groupId: "",
                    departId: "",
                    key: "",
                    orderCode: "",
                    GoodSelector: "",
                    SupplierSelector: "",
                    StoreSelector: "",
                    receiveKey: "",
                    cateID: "",
                    SelfCode: ""
                },
                page: {
                    curr: 1 //重新从第1页开始
                }
            });
        });

        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            var dataTime = $("#test6").val();

            if (dataTime) {
                var times = dataTime.split('~');
                field["startTime"] = times[0].trim();
                field["endTime"] = times[1].trim();
            }
            else {
                field["startTime"] = "";
                field["endTime"] = "";
            }


            //执行重载
            table.reload(layui.data["currentTable"], {
                where: {
                    startTime: field["startTime"],
                    endTime: field["endTime"],
                    key: field["key"],
                    SelfCode: field["SelfCode"],
                    orderCode: field["orderCode"],
                    GoodSelector: field["GoodSelector"],
                    SupplierSelector: field["SupplierSelector"],
                    StoreSelector: field["StoreSelector"],
                    receiveKey: field["receiveKey"],
                    cateID: field["cateID"]
                },
                page: {
                    curr: 1 //重新从第1页开始
                }
            });

            var data = {
                state: layui.data["currentTableIndex"],
                startTime: field["startTime"],
                endTime: field["endTime"],
                key: field["key"],
                orderCode: field["orderCode"],
                GoodSelector: field["GoodSelector"],
                SupplierSelector: field["SupplierSelector"],
                StoreSelector: field["StoreSelector"],
                receiveKey: field["receiveKey"],
                cateID: field["cateID"]
            }

            //statice(data);
        });
    })
</script>